package com.ems.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ems.entity.TProduct;
import com.ems.entity.TRoler;
import com.ems.entity.TUser;
import com.ems.entity.TUserRole;
import com.ems.mapper.TProductMapper;
import com.ems.mapper.TUserMapper;
import com.ems.service.TUserService;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZZH
 * @since 2022-06-27
 */
@Service
public class TUserServiceImpl extends ServiceImpl<TUserMapper, TUser> implements TUserService {

    @Autowired
    TUserMapper tUserMapper;

    //增
    @Override
    @Transactional
    public Boolean add(TUser tUser){
        baseMapper.add1(tUser);
        String f =tUser.getUserName();
        int g = tUser.getRoleId();
        String d = tUser.getCreator();
        String e = tUser.getRemarks();
        baseMapper.add2(f,g,d,e);
        return true;
    }

    //删
    @Override
    @Transactional
    public Boolean delete(String userName){
         baseMapper.delete(userName);
         baseMapper.delete2(userName);
         return true;
    }

    //改
    @Override
    @Transactional
    public Boolean update(TUser tUser){
        baseMapper.update1(tUser);
        String i =tUser.getUserName();
        int j = tUser.getRoleId();
        String a = tUser.getCreator();
        String b = tUser.getUpdater();
        String c = tUser.getRemarks();
        baseMapper.update2(i,j,a,b,c);
        return true;
    }

    //查单
    @Override
    public TUser findOne(String userName){
        return baseMapper.findOne(userName);
    }

    //查全
    @Override
    public List<TUser> findAll(){
        return  baseMapper.findAll();
    }

    //登录
    @Override
    public TUser login(String userName,String password){
        return baseMapper.login(userName,password);
    }

    //注册
    @Override
    @Transactional
    public void register(TUser tUser){
        baseMapper.register(tUser);
        String q=tUser.getUserName();
        int w = 3;
        String r =tUser.getCreator();
        baseMapper.register2(q,w,r);
    }

    //注册验证
    @Override
    public TUser registerTest(String userName){
        return baseMapper.registerTest(userName);
    }
}
